from django.db import models
from drf_shop_admin.utils.models import BaseModel

# Create your models here.
class Orders(BaseModel):
    """
    订单表
    """
    PAY_CHOICES = (
        (0, '未支付'),
        (1, '支付宝'),
        (2, '微信'),
        (3, '银行卡')
    )
    PAY_STATUS_CHOICES = (
        (0, '未付款'),
        (1, '已付款')
    )
    IS_SEND_CHOICES = (
        (True, '已发货'),
        (False, '未发货')
    )
    FA_PIAO_TITLE_CHOICES = (
        ('gs', '公司'),
        ('gr', '个人')
    )
    number = models.UUIDField('订单编号', unique=True)
    price = models.DecimalField('订单总金额', max_digits=10, decimal_places=2, default=0.00, null=False)
    pay = models.SmallIntegerField('支付方式', default=0, choices=PAY_CHOICES)
    is_send = models.BooleanField('订单是否发货', default=False, choices=IS_SEND_CHOICES, null=False)
    trade_no = models.CharField('支付宝交易流水号码', max_length=32, blank='', null=False)
    fapiao_title = models.CharField('发票抬头公司/个人', max_length=32, default='公司', choices=FA_PIAO_TITLE_CHOICES, null=False)
    fapiao_company = models.CharField('公司名称', max_length=32, blank=True, null=False)
    fapiao_content = models.CharField('发票内容', max_length=32, blank=True, null=False)
    consignee_addr = models.TextField('收货人地址', blank=True, null=False)
    pay_status = models.SmallIntegerField('订单状态', default=0, null=False, choices=PAY_STATUS_CHOICES)
    user = models.ForeignKey('users.User', on_delete=models.CASCADE, verbose_name='商品用户')
    good = models.ManyToManyField('goods.Goods', blank=True, related_name='order', verbose_name='订单商品')

    objects = models.Manager()

    def __str__(self):
        return self.user.username

    class Meta:
        verbose_name = '商品订单'
        verbose_name_plural = verbose_name
        ordering = ['id']